'''
Created on 2011-01-06

@author: Michal Kolodziejski
'''
from word import Word


'''
Klasa dokumentu
'''
class Document(object):

    def __init__(self, path):
        self.path=path
        self.metadataWords=[]
        self.titleWords=[]
        self.words={}
        self.allWordsCount=0
        #wspolczynnik istotnosci danego slowa w tym dokumencie
        #self.tfidf = []
    
        
    def addMetadataWord(self, word):
        self.metadataWords.append(word.lower())
    
    def addMetadataWords(self, words):
        for w in words:
            self.metadataWords.append(w.lower())
            
    def setMetadataWords(self, words):
        self.metadataWords = []
        for w in words:
            self.metadataWords.append(w.lower())
    
    
    def addTitleWord(self, word):
        self.titleWords.append(word.lower())
        
        
    def addWord(self, word):
        aWord=Word(word)
        if self.words.has_key(word):
            aWord=self.words[word]
        
        #zwiekszenie wszystkich wystapien slowa
        aWord.incrementCount()
        self.words[word]=aWord
        
        self.allWordsCount+=1
    
    
    def addTitleWords(self, words):
        for w in words:
            self.titleWords.append(w.lower())
            
    def setTitleWords(self, words):
        self.titleWords = []
        for w in words:
            self.titleWords.append(w.lower())
    
    
    def getPath(self):
        return self.path
        
    def getWords(self):
        return self.words
        
    def getMetadataWords(self):
        return self.metadataWords
    
    def getTitleWords(self):
        return self.titleWords
    
    def getAllWordsCount(self):
        return self.allWordsCount
    
    
    def containsWord(self, word):
        if self.words.has_key(word):
            return True
        return False
    
    
    def getWordCounter(self, word):
        if self.words.has_key(word):
            return self.words[word].getCount()
        else:
            return 0
        
        
#    def addTfidf(self, number):
#        self.tfidf.append(number)
#        
#    def getTfidfVector(self):
#        return self.tfidf
#    
#    def setTfifs(self, tfs):
#        self.tfidf = tfs
    
#    def getMostTfidf(self):
#        m = max(self.tfidf)
#        if m == 0:
#            return -1
#        return self.tfidf.index(m)
    
    
    def __eq__(self, other):
        if self.path == other.path:
            return True
        return False
    
    def __ne__(self, other):
        if self.path != other.path:
            return True
        return False
    